package com.itheima.fanshe2;

import java.lang.reflect.Field;

public class Demo05 {

    public static void main(String[] args) throws Exception {
        Class<Student> clazz = Student.class;
        Student student = clazz.getConstructor().newInstance();//创建对象
        Field name = clazz.getDeclaredField("name");
        //第一个参数 说明我们在操作哪一个对象
        // 第二个参数 就是想要设置的值
        name.setAccessible(true);//私有属性设置值 必须先 暴力反射
        name.set(student,"坤坤");
        System.out.println(student);
        Object o = name.get(student);
        System.out.println(o);

        Field address = clazz.getField("address");
        address.set(student,"淖马村");

        Object o1 = address.get(student);
        System.out.println(o1);


    }
}
